package com.github.cosycode.imgtool.tool;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import javax.activation.MimetypesFileTypeMap;
import java.io.File;

/**
 * <b>Description : </b>
 * <p>
 * <b>created in </b> 2022/1/6
 * </p>
 *
 * @author CPF
 * @since 1.0
 **/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ImageCheckTool {
    public static final String MIME_TYPES = "image png tif jpg jpeg bmp svg";
    private static final MimetypesFileTypeMap meType;

    static {
        meType = new MimetypesFileTypeMap();
        meType.addMimeTypes(MIME_TYPES);
    }

    public static boolean isImage(File file) {
        String mimetype = meType.getContentType(file);
        String type = mimetype.split("/")[0];
        return type.equals("image");
    }

}
